﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WJP.Logging
{
    [Serializable]
    public abstract class AbstractLoggerFactory : ILoggerFactory
    {
        public virtual ILogger Create(Type type)
        {
            if (type == null)
                throw new ArgumentNullException(nameof(type));

            return Create(type.FullName);
        }

        public ILogger Create(Type type, LogLevel level)
        {
            if (type == null)
                throw new ArgumentNullException(nameof(type));

            return Create(type.FullName, level);
        }

        public abstract ILogger Create(string name);

        public abstract ILogger Create(string name, LogLevel level);

        /// <summary>
        /// 获取配置文件信息
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        protected static FileInfo GetConfigFile(string fileName)
        {
            FileInfo result;
            if (Path.IsPathRooted(fileName))
            {
                result = new FileInfo(fileName);
            }
            else
            {
                result = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName));
            }
            return result;
        }
    }
}
